import Router from 'koa-router';
import proxyService from '../../../common/proxyService';
import {
  getMissionRewardsPage,
  getMissionCompletedPage,
  getMissionRewardsInfo,
  getActivityByMrId,
  deleteMissionRewards,
  saveOrUpdateInviteAttentionReward,
  updateWriteOff,
  getMissionCompletedStatistics,
  getGoodsList,
  updateBargainRewards,
} from '../../../api';

const router = new Router();

//
router.get('/getMissionRewardsPage', async ctx => {
  console.log(ctx.request.query);
  const response = await proxyService.postProxy(ctx, getMissionRewardsPage);
  return (ctx.body = response);
});

//
router.get('/getMissionCompletedPage', async ctx => {
  const params = {
    ...ctx.request.query,
    missionId: parseInt(ctx.request.query.missionId),
  };
  const response = await proxyService.postProxy(ctx, getMissionCompletedPage, { params });
  return (ctx.body = response);
});

//
router.get('/getMissionRewardsInfo', async ctx => {
  const response = await proxyService.postProxy(ctx, getMissionRewardsInfo);
  return (ctx.body = response);
});

//
router.get('/getActivityByMrId', async ctx => {
  const response = await proxyService.postProxy(ctx, getActivityByMrId);
  return (ctx.body = response);
});

router.get('/getGoodsList', async ctx => {
  const response = await proxyService.postProxy(ctx, getGoodsList);
  return (ctx.body = response);
});

//
router.post('/deleteMissionRewards', async ctx => {
  const response = await proxyService.postProxy(ctx, deleteMissionRewards);
  return (ctx.body = response);
});

//
router.post('/saveOrUpdateInviteAttentionReward', async ctx => {
  const response = await proxyService.postProxy(ctx, saveOrUpdateInviteAttentionReward);
  return (ctx.body = response);
});

router.post('/updateBargainRewards', async ctx => {
  const response = await proxyService.postProxy(ctx, updateBargainRewards);
  return (ctx.body = response);
});

//
router.post('/updateWriteOff', async ctx => {
  const response = await proxyService.postProxy(ctx, updateWriteOff);
  return (ctx.body = response);
});

router.get('/getMissionCompletedStatistics', async ctx => {
  const response = await proxyService.postProxy(ctx, getMissionCompletedStatistics);
  return (ctx.body = response);
});

export default router;
